package com.tgky.ybzb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tgky.ybzb.entity.ZstpType;
import com.tgky.ybzb.mapper.ZstpTypeMapper;
import com.tgky.ybzb.service.ZstpTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 知识图谱类型表（树表）(ZstpType)表服务实现类
 *
 * @author makejava
 * @since 2024-09-06 10:25:23
 */
@Service
public class ZstpTypeServiceImpl extends ServiceImpl<ZstpTypeMapper, ZstpType> implements ZstpTypeService {

    @Resource
    private ZstpTypeMapper zstpTypeMapper;
    /**
     * 查出所有知识类型对象
     * @param zstpType
     * @return
     */
    @Override
    public List<ZstpType> selectAllList(ZstpType zstpType) {
        QueryWrapper<ZstpType> zstpTypeQueryWrapper=new QueryWrapper<>();
        zstpTypeQueryWrapper.eq("parent_id",0);
        zstpTypeQueryWrapper.orderByAsc("sort");
        List<ZstpType> zstpTypeList=zstpTypeMapper.selectList(zstpTypeQueryWrapper);
        getChildNode(zstpTypeList);
        return zstpTypeList;
    }

    /**
     * 递归获取所有子集
     */
    public void getChildNode(List<ZstpType> zstpTypeList){
        if (zstpTypeList==null || zstpTypeList.size()<=0){
            return;
        }
        for(ZstpType zstpType:zstpTypeList){
            QueryWrapper<ZstpType> zstpWapper=new QueryWrapper<>();
            zstpWapper.eq("parent_id",zstpType.getId());
            zstpWapper.orderByAsc("sort");
            List<ZstpType> childList=zstpTypeMapper.selectList(zstpWapper);
            zstpType.setChildrenList(childList);
            getChildNode(zstpType.getChildrenList());
        }
    }
}

